package com.smartfast4j.backend.modules.sys.controller;


import com.smartfast4j.backend.common.bean.R;
import com.smartfast4j.backend.common.controller.WebBaseController;
import com.smartfast4j.backend.modules.sys.entity.SysUser;
import com.smartfast4j.backend.modules.sys.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 系统用户 前端控制器
 * </p>
 *
 * @author 孤傲苍狼
 * @since 2017-09-05
 */
@RestController
@RequestMapping("/sys/sysUser")
public class SysUserController extends WebBaseController {

    @Autowired
    private SysUserService sysUserService;

    @RequestMapping("/getSysUserList")
    public List<SysUser> getSysUserList() {
        Map<String,Object> parmMap = new HashMap<>();
        parmMap.put(SysUser.USER_ID,1);
        List<SysUser> sysUserList = sysUserService.selectByMap(parmMap);
        return sysUserList;
    }

    /**
     * 获取登录的用户信息
     */
    @RequestMapping("/info")
    public R info(){
        return R.ok().putEncrypt("user", getSysLoginUser());
    }

    /**
     * 修改登录用户密码
     */
    @RequestMapping("/password")
    public R password(String password, String newPassword){
        //更新密码
        int count = sysUserService.updatePassword(getSysLoginUserId(), password, newPassword);
        if(count == 0){
            return R.error("原密码不正确");
        }
        return R.ok("修改成功");
    }
}
